<?php
/**
 * 广告位管理
 */
namespace app\admins\controller\set;
use \app\admins\controller\Auth;
class Adposition extends Auth{
    
    /**
     * 列表
     */
    public function index(){
        $channelList = config('servces.site_channel_list');
        $platList = config('servces.site_plat_list');
        $where = [
            'page'      => input('page',1),
            'keyword'   => input('keyword'),
            'status'    => input('status'),
            'channe'    => input('channe'),
            'plat'      => input('plat',2),
        ];
        
        $Adposition = new \logic\set\ad\Adposition($this->getUser());
        $data = $Adposition->getList($where);
        $showpage = showpage($data['total'],$data['page'],$data['limit']);
        $this->assign(get_defined_vars());
        return $this->fetch();
    }
    
    /**
     * 添加
     */
    public function add(){        
        try{
            if( request()->isPost() ){                
                $param = array(
                    'plat'      => input('plat'),
                    'channel'   => input('channel'),
                    'tag'       => input('tag'),
                    'name'      => input('name'),
                    'height'    => input('height'),
                    'width'     => input('width'),
                    'des'       => input('des'),
                    'limitnum'  => input('limitnum'),
                    'showpage'  => input('showpage'),
                );
                $Adposition = new \logic\set\ad\Adposition($this->getUser());
                $Adposition->add($param);
                return $this->success('添加成功','/set/adposition/index');
            }
            $channel = config('servces.site_channel_list');
            $this->assign(get_defined_vars());
            return $this->fetch();
        }catch(\think\Exception $e){
            $this->error($e->getMessage());
        }
    }
    
    /**
     * 编辑
     */
    public function edit(){
        try{
            $id = input('id');
            if( request()->isPost() ){                
                $param = array(
                    'plat'      => input('plat'),
                    'channel'   => input('channel'),
                    'tag'       => input('tag'),
                    'name'      => input('name'),
                    'height'    => input('height'),
                    'width'     => input('width'),
                    'des'       => input('des'),
                    'limitnum'  => input('limitnum'),
                    'showpage'  => input('showpage'),
                );
                $Adposition = new \logic\set\ad\Adposition($this->getUser());
                $Adposition->edit($id,$param);
                return $this->success('修改成功','/set/adposition/index');
            }
            $channel = config('servces.site_channel_list');
            $Adposition = new \logic\set\ad\Adposition($this->getUser());
            
            $data = $Adposition->find(['id'=>$id]);
            $this->assign(get_defined_vars());
            return $this->fetch();
        }catch(\think\Exception $e){
            $this->error($e->getMessage());
        }
    }
    
    /**
     * 修改状态
     */
    public function editstatus(){
        try{
            $id = input('id');
            $AdminManage = new \logic\set\ad\Adposition($this->getUser());
            $result = $AdminManage->editStatus($id);
            return $this->success('成功');
        }catch(Exception $e){
            return $this->error('失败');
        }
    }
}